#include "Drawable.h"
/*******************************************************************
* Constructor
*******************************************************************/
Drawable::Drawable(ID3DX10Mesh* mesh, Material* mat, ID3D10EffectShaderResourceVariable* pTexSR, ID3D10ShaderResourceView* tex, D3D10_TECHNIQUE_DESC *tD, D3DXMATRIX worldMatrix)
{
	//set Mesh
	myMesh = mesh;
	//set Material
	material = mat;
	//set texture
	pTextureSR = pTexSR;
	pTextureSR->SetResource(tex);
	//set Rendering Algorithm
	memcpy(&techDesc, tD, sizeof(techDesc));
	//Set Positionmatrix
	memcpy(&positionMatrix, &worldMatrix, sizeof(positionMatrix));
	
}
/*******************************************************************
* Destructor
*******************************************************************/
Drawable::~Drawable()
{

}
void Drawable::draw(ID3D10Device* pD3DDevice, ID3D10Effect*	pBasicEffect) {
	pWorldMatrixEffectVariable = pBasicEffect->GetVariableByName( "World" )->AsMatrix();
	//set Materialproperties
	pBasicEffect->GetVariableByName( "material" )->SetRawValue(&material, 0, sizeof(Material));
	//Positioning
	pWorldMatrixEffectVariable->SetMatrix(positionMatrix);
	for( UINT p = 0; p < techDesc.Passes; p++ )
	{
		//apply technique
		pBasicEffect->GetTechniqueByName(techDesc.Name)->GetPassByIndex( p )->Apply( 0 );
		myMesh->DrawSubset(0);
	}
}
void Drawable::multiply(D3DXMATRIX *mul) {
	D3DXMatrixMultiply(&positionMatrix,&positionMatrix,mul);
}
D3DXMATRIX* Drawable::getPosMatrix() {
	return &positionMatrix;
}